package w3

class Person1(val page: Int, val pname: String) {

  def sayHello() = println(s"my name is ${pname},and is ${page} years old")
}

class Children1(override val page: Int, override val pname: String) extends Person1(page, pname) {


  override def sayHello() = {
    println(s"我的名字是${pname},今年${page}")
    super.sayHello()
  }
}

object JichengExample2 {
  def main(args: Array[String]): Unit = {
    var p1 = new Children1(21, "老吴")
    p1.sayHello()
    var p2: Person1 = new Children1(23, "小张")
    p2.sayHello() //21 or 18?
    println("11111111111111111111111111")
    //匿名子类
    var p3 = new Children1(21, "小王") {
      override def sayHello() = {
        println(s"这个老不死的已经：")
        super.sayHello()
      }
    }
    p3.sayHello()
  }
}
